cmake_minimum_required(VERSION 3.5)
project(Chicken)

# 设置 C++ 标准为 C++11
set(CMAKE_CXX_STANDARD 11)

# 添加可执行文件
add_executable(chicken main.cpp)

# 定义用户输入的安装目录变量
set(INSTALL_DIR "" CACHE STRING "Installation directory")

# 设置安装路径
install(TARGETS chicken DESTINATION "${INSTALL_DIR}/bin")
install(FILES Chicken.h DESTINATION "${INSTALL_DIR}/include")

# 检查是否已找到 Doxygen 工具
find_package(Doxygen)
if(Doxygen_FOUND)

  # 配置 Doxyfile
  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)

  # 添加一个新的 target 来生成文档
  add_custom_target(docs
    COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    COMMENT "Generating Doxygen Documentation"
    VERBATIM
  )

  # 将文档 target 添加到默认构建目标中
  add_dependencies(chicken docs)

  # 在安装时复制生成的文档
  install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/docs DESTINATION "${INSTALL_DIR}")
else()
  message(WARNING "Doxygen not found. Documentation generation disabled.")
endif()
